package cn.iocoder.yudao.module.famous.doctor.controller.app.casehistory;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.casehistory.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.casehistory.CaseHistoryConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.casehistory.CaseHistoryDO;
import cn.iocoder.yudao.module.famous.doctor.service.casehistory.CaseHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 我的病历")
@RestController
@RequestMapping("/famous.doctor/case-history/app")
@Validated
public class AppCaseHistoryController {

    @Resource
    private CaseHistoryService caseHistoryService;

    @PostMapping("/create")
    @Operation(summary = "创建我的病历")
    public CommonResult<Long> createCaseHistory(@Valid @RequestBody CaseHistoryCreateReqVO createReqVO) {
        return success(caseHistoryService.createCaseHistory(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新我的病历")
    public CommonResult<Boolean> updateCaseHistory(@Valid @RequestBody CaseHistoryUpdateReqVO updateReqVO) {
        caseHistoryService.updateCaseHistory(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除我的病历")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCaseHistory(@RequestParam("id") Long id) {
        caseHistoryService.deleteCaseHistory(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得我的病历")
    public CommonResult<CaseHistoryRespVO> getCaseHistory(@RequestParam("id") Long id) {
        CaseHistoryDO caseHistory = caseHistoryService.getCaseHistory(id);
        return success(CaseHistoryConvert.INSTANCE.convert(caseHistory));
    }

    @GetMapping("/list")
    @Operation(summary = "获得我的病历列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<CaseHistoryRespVO>> getCaseHistoryList(@RequestParam("ids") Collection<Long> ids) {
        List<CaseHistoryDO> list = caseHistoryService.getCaseHistoryList(ids);
        return success(CaseHistoryConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得我的病历分页")
    public CommonResult<PageResult<CaseHistoryRespVO>> getCaseHistoryPage(@Valid CaseHistoryPageReqVO pageVO) {
        PageResult<CaseHistoryDO> pageResult = caseHistoryService.getCaseHistoryPage(pageVO);
        return success(CaseHistoryConvert.INSTANCE.convertPage(pageResult));
    }

}
